<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.welfare.admin.service.*" %>
<%

	HashList codeUseYn	= CommonUtil.getCodeList("use_yn");			//사용여부
	HashList codeOpenYn	= CommonUtil.getCodeList("open_yn", "전체");	//공개여부
	HashList code003	= CommonUtil.getCodeList("003", "전체");		//서비스유형
	HashList code002	= CommonUtil.getCodeList("002");		//사업구분
	HashList code004	= CommonUtil.getCodeList("004");		//공급주체
	
	HashList code501	= CommonUtil.getCodeList("501");	//생애주기
	HashList code502	= CommonUtil.getCodeList("502");	//대상특성
	HashList code503	= CommonUtil.getCodeList("503");	//가구유형
	HashList code504	= CommonUtil.getCodeList("504");	//소득구분
	HashList code505	= CommonUtil.getCodeList("505");	//지원형태
	HashList code506	= CommonUtil.getCodeList("506");	//욕구
	
	HashList code005	= CommonUtil.getCodeList("005");	//교육기간
	HashList code507	= CommonUtil.getCodeList("507");	//교육시간
	HashList code508	= CommonUtil.getCodeList("508");	//교육요일
	
	
	HashBox box = new HashBox(request);

	String s_service_gubn		= box.getCheckedValue("s_service_gubn");
	String s_srch_age			= box.getCheckedValue("s_srch_age");
	String s_srch_target		= box.getCheckedValue("s_srch_target");
	String s_srch_family		= box.getCheckedValue("s_srch_family");
	String s_srch_income		= box.getCheckedValue("s_srch_income");
	String s_srch_support		= box.getCheckedValue("s_srch_support");
	String s_srch_needs			= box.getCheckedValue("s_srch_needs");
	String s_srch_period		= box.getCheckedValue("s_srch_period");
	String s_srch_time			= box.getCheckedValue("s_srch_time");
	String s_srch_weekday		= box.getCheckedValue("s_srch_weekday");
	
	String s_service_type		= StringUtil.nvl(request.getParameter("s_service_type"));
	String s_service_name		= StringUtil.nvl(request.getParameter("s_service_name"));
	String s_service_info		= StringUtil.nvl(request.getParameter("s_service_info"));
	String s_dept_name			= StringUtil.nvl(request.getParameter("s_dept_name"));
	String s_open_yn			= StringUtil.nvl(request.getParameter("s_open_yn"));
	String s_use_yn				= StringUtil.nvl(request.getParameter("s_use_yn"), "Y");
	
	String curr_page 			= StringUtil.nvl(request.getParameter("curr_page"), "1");
	String sort_col				= StringUtil.nvl(request.getParameter("sort_col"), "to_number(service_id)");
	String sort_asc				= StringUtil.nvl(request.getParameter("sort_asc"), "asc");


	HashMap infos = new HashMap();
	infos.put("service_type",	s_service_type);
	infos.put("srch_service_gubn",	s_service_gubn);
	infos.put("srch_age",		s_srch_age);
	infos.put("srch_target",	s_srch_target);
	infos.put("srch_family",	s_srch_family);
	infos.put("srch_income",	s_srch_income);
	infos.put("srch_support",	s_srch_support);
	infos.put("srch_needs",		s_srch_needs);
	
	infos.put("prg_period",		s_srch_period);
	infos.put("srch_time",		s_srch_time);
	infos.put("srch_weekday",	s_srch_weekday);
	
	infos.put("service_name",	s_service_name);
	infos.put("service_info",	s_service_info);
	infos.put("dept_name",		s_dept_name);
	infos.put("open_yn",		s_open_yn);
	infos.put("use_yn",			s_use_yn);
	
	//paging
	infos.put("line_per_page",	"10");	
	infos.put("curr_page",		curr_page);
	infos.put("sort_col", 		sort_col);
	infos.put("sort_asc", 		sort_asc);

	ServiceDAO dao 	= new ServiceDAO();
	HashList list 	= dao.selectServiceList(infos);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= SYSTEM_NAME %> 관리자</title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#s_name').focus().select();
		$('#list').find('tr').hover(
				function () { $(this).addClass("hover"); }
			  , function () { $(this).removeClass("hover"); }
			)
			.click(function(){
				var serviceId = $(this).find('.service_id').text();
				cfOpen('serviceInfo.jsp?service_id=' + serviceId, 'service'+$.trim(serviceId), 1024, 768);
			});
		
		$('.chkall').change(function(e) {
			if ($(this).attr('checked') == 'checked') {
				$(this).closest('td').find('input[type="checkbox"]').each(function() {
					if ($(this).attr('id').indexOf('_all') < 0) {
						$(this).attr('checked', true);
					}
				});
			} else {
				$(this).closest('td').find('input[type="checkbox"]').each(function() {
					if ($(this).attr('id').indexOf('_all') < 0) {
						$(this).attr('checked', false);
					}
				});
			}
		});
		
		$('.sort').on('click', function() {
			document.searchForm.sort_col.value = $(this).attr('id');
			document.searchForm.sort_asc.value = 'asc';
			document.searchForm.submit();
		});
		

		$('.asc').on('click', function() {
			document.searchForm.sort_col.value = $(this).attr('id');
			document.searchForm.sort_asc.value = 'desc';
			document.searchForm.submit();
		});
		
		$('.desc').on('click', function() {
			document.searchForm.sort_col.value = '';
			document.searchForm.sort_asc.value = '';
			document.searchForm.submit();
		});
	});


	function fnSearch(currPage) {
		$('#searchForm').attr('action', './serviceList.jsp?curr_page=' + currPage);
		$('#searchForm').submit();
	}
	
	function fnInit() {
		$('#searchForm').find('input[type="checkbox"]').attr('checked', false);
		$('#searchForm').find('input[type="text"]').val('');
		$('#searchForm').find('input[name="s_service_type"]').eq(0).attr('checked', true);
		$('#searchForm').find('input[name="s_open_yn"]').eq(0).attr('checked', true);
	}

	function fnExcel() {
		$('#searchForm').attr('action', './serviceExcel.jsp');
		$('#searchForm').submit();
		$('#searchForm').attr('action', './serviceList.jsp');
	}
	
	function fnCallBackSearch() {
		fnSearch(1);
	}
	</script>
</head>
<body>
<div id="wrap">
	<%-- <div id="top">
		<%@ include file="/admin/include/top.jsp" %>
	</div> --%>
	<div id="page">
		<%-- <div id="menu">
			<%@ include file="/admin/include/leftMenu.jsp" %>
		</div> --%>
		<div id="contents_nowidth">
			<div class="menu_title">
				<h1>복지자원검색</h1>
				<p>관리자 > 복지자원관리 > <b>복지자원검색</b></p>
			</div>
			<div class="clear line_01"></div>

			<form name="searchForm" id="searchForm" method="post" action="./serviceList.jsp">
			<input type="hidden" name="sort_col" value="<%= sort_col %>"/>
			<input type="hidden" name="sort_asc" value="<%= sort_asc %>"/>
			
			<table cellpadding="0" cellspacing="0" class="table_01 mt15">
			<colgroup>
				<col width="100px" />
				<col  />
				<col width="100px" />
				<col  />
			</colgroup>
			<tbody id="search">
				<tr>
					<th><p>사업구분</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_service_gubn_all" value=""/><label for="s_service_gubn_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code002, "s_service_gubn", s_service_gubn) %>
					</td>
					<th><p>서비스유형</p></th>
					<td class="brx">
						<%= StringUtil.makeRadio(code003, "s_service_type", s_service_type) %>
					</td>
				</tr>
				<tr>
				</tr>
				<tr>
					<th><p>생애주기</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_age_all" value=""/><label for="s_srch_age_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code501, "s_srch_age", s_srch_age) %>
					</td>
					<th><p>서비스명</p></th>
					<td class="brx">
						<input type="text" name="s_service_name" value="<%= s_service_name %>" class="w200"/>
					</td>
				</tr>
				<tr>
					<th><p>대상특성</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_target_all" value=""/><label for="s_srch_target_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code502, "s_srch_target", s_srch_target) %>
					</td>
					<th><p>서비스내용</p></th>
					<td class="brx">
						<input type="text" name="s_service_info" value="<%= s_service_info %>" class="w200"/>
					</td>
				</tr>
				<tr>
					<th><p>가구유형</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_family_all" value=""/><label for="s_srch_family_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code503, "s_srch_family", s_srch_family) %>
					</td>
					<th><p>담당부서</p></th>
					<td class="brx">
						<input type="text" name="s_dept_name" value="<%= s_dept_name %>" class="w200"/>
					</td>
				</tr>
				<tr>
					<th><p>소득구분</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_income_all" value=""/><label for="s_srch_income_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code504, "s_srch_income", s_srch_income) %>
					</td>
					<th><p>교육기간</p></th>
					<td class="brx">
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_period_all" value=""/><label for="s_srch_period_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code005, "s_srch_period", s_srch_period) %>
					</td>
				</tr>
				<tr>
					<th><p>지원형태</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_support_all" value=""/><label for="s_srch_support_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code505, "s_srch_support", s_srch_support) %>
					</td>
					<th><p>교육시간</p></th>
					<td class="brx">
						<span class="checkbox"><nobr><input class="chkall" type="checkbox" id="s_srch_time_all" value=""/><label for="s_srch_time_all">전체</label></nobr></span>
		                <%= CommonUtil.makeCheckBox(code507, "s_srch_time", s_srch_time) %>
					</td>
				</tr>
				<tr>
					<th><p>욕구</p></th>
					<td>
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_needs_all" value=""/><label for="s_srch_needs_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code506, "s_srch_needs", s_srch_needs) %>
					</td>
					<th><p>교육요일</p></th>
					<td class="brx">
						<span class="checkbox"><input class="chkall" type="checkbox" id="s_srch_weekday_all" value=""/><label for="s_srch_weekday_all">전체</label></span>
		                <%= CommonUtil.makeCheckBox(code508, "s_srch_weekday", s_srch_weekday) %>
					</td>
				</tr>
				<tr>
					<th><p>공개여부</p></th>
					<td>
						<%= StringUtil.makeRadio(codeOpenYn, "s_open_yn", s_open_yn) %>
					</td>
		<%	if (isAdmin) { %>
					<th><p>사용여부</p></th>
					<td class="brx">
						<%= StringUtil.makeRadio(codeUseYn, "s_use_yn", s_use_yn) %>
					</td>
		<%	} else {	%>
					<th><p></p></th>
					<td class="brx"></td>
		<%	}	%>
				</tr>
			</tbody>
			</table>
			

			<div class="mt10 mb10 r">
				<input type="image" class="button" src="../images/btn_search.gif"/>
				<a href="#nohref" onclick="fnInit()"><img src="../images/btn_init.gif"/></a>
				<a href="#nohref" onclick="fnExcel()"><img src="../images/btn_excel.gif"/></a>
			</div>

			</form>



			<div class="search_result">검색결과 : <%= StringUtil.toPrice((String)infos.get("total_count")) %>건</div>

		    <table width="100%" cellpadding="0" cellspacing="0" class="table_04">
				<colgroup>
					<col width="60px"/>
					<col width="100px"/>
					<col />
					<col width="200px"/>
					<col width="160px"/>
					<col width="60px"/>
					<col width="60px"/>
					<col width="60px"/>
					<col width="100px"/>
				</colgroup>
				<thead>
					<tr> 
						<th><p>번호</p></th>
						<th class="l <%= "service_gubn".equals(sort_col) ? sort_asc : "sort" %>" id="service_gubn"><p>사업구분</p></th>
						<th class="l <%= "service_name".equals(sort_col) ? sort_asc : "sort" %>" id="service_name"><p>서비스명</p></th>
						<th class="l <%= "dept_name".equals(sort_col) ? sort_asc : "sort" %>" id="dept_name"><p>담당부서</p></th>
						<th class="l <%= "tel_no".equals(sort_col) ? sort_asc : "sort" %>" id="tel_no"><p>연락처</p></th>
						<th class="c <%= "hit_count".equals(sort_col) ? sort_asc : "sort" %>" id="hit_count"><p>조회</p></th> 
						<th><p>공개</p></th>
						<th><p>사용</p></th>
						<th class="c <%= "mod_date".equals(sort_col) ? sort_asc : "sort" %>" id="mod_date"><p>최종수정일</p></th>
					</tr>
				</thead>
				<tbody id="list">
			<%	for (int i = 0; i < list.size(); i++) { %>
					<tr>
						<td class="service_id">
							<%= list.get("service_id", i) %>
						</td>
						<td class="l"><%= list.get("service_gubn", i) %></td>
						<td class="l service_name"><%= list.get("service_name", i) %></td>
						<td class="l"><%= list.get("dept_name", i) %></td>
						<td class="l"><%= list.get("tel_no", i) %></td>
						<td><%= list.get("hit_count", i) %></td>
						<td><%= list.get("open_yn", i) %></td>
						<td><%= list.get("use_yn", i) %></td>
						<td><%= list.get("mod_date", i) %></td>
					</tr>
			<%	} %>
				</tbody>
			</table>
			
			<div class="pagination">
				<%= StringUtil.getPageHtml(infos) %>
			</div>

		</div>
	</div>
</div>
</body>
</html>
